home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 68 / Mac Magazin CD 68.iso / macware / KillTemporaryItems ƒ / KillTemporaryItems.c next >
Encoding:
C/C++ Source or Header  |  2000-03-18  |  5.0 KB  |  207 lines  |  [TEXT/CWIE]

  1. // KillTemporaryItems.c
  2. // 17 March 2000
  3. // d.c.oshel
  4. //
  5. // Happy St. Patrick's Day
  6. //
  7. // This moves non-busy items in OS 9's broken "Temporary Items" folder to the desktop.  
  8. //
  9. // CAUTION:  ABSOLUTELY NO WARRANTY OR SUPPORT - 
  10. //           USE THIS UTILITY AT YOUR OWN RISK AND DISCRETION!
  11. //
  12. // Changes:
  13. // v1.0b2 - 18 mar 2000 dco - fixed loop error, only moving one file at a time;
  14. //                            removed beep, should be a noop if nothing happens
  15.  
  16.  
  17. /*------------------------------------------------------------------------------
  18. #
  19. #    Macintosh Developer Technical Support
  20. #
  21. #    Simple Color QuickDraw Sample Application
  22. #
  23. #    SillyBalls
  24. #
  25. #    SillyBalls.c    -    C Source
  26. #
  27. #    Copyright © 1988 Apple Computer, Inc.
  28. #    All rights reserved.
  29. #
  30. #    Versions:    1.0                    8/88
  31. #
  32. #    Components:    SillyBalls.c        August 1, 1988
  33. #                SillyBalls.make        August 1, 1988
  34. #
  35. #    This is a very simple sample program that demonstrates how to use Color 
  36. #    QuickDraw.  It is about two pages of code, and does nothing more than open
  37. #    a color window and draw randomly colored ovals in the window.
  38. #    
  39. #    The purpose is to show how to get some initial results with Color QuickDraw.
  40. #    It is a complete program and is very short to be as clear as possible.
  41. #    
  42. #    It does not have an Event Loop.  It is not fully functional in the sense that
  43. #    it does not do all the things you would expect a well behaved Macintosh 
  44. #    program to do, like size the window naturally, have an event loop, use menus, 
  45. #    etc.
  46. #
  47. #    See Sample and TESample for the general structure and MultiFinder techniques that
  48. #    we recommend that you use when building a new application.
  49. #
  50. ------------------------------------------------------------------------------*/
  51.  
  52.     
  53. //    Version 1.0:    6/2/88
  54. //                    7/20/88     DJB    Converted to C
  55. //    
  56. //    purpose        To demonstrate a simple color App using Color QuickDraw.
  57. //                        It draws colored balls in a color window, then uses colored
  58. //                        text inverted in the ball.  The ball location and color is Random.
  59. //                        
  60. //                        This program was written by Bo3b Johnson, 1/88.
  61. //                        
  62. //                        The inverted Bob text was a Skippy Blair special concept,
  63. //                        kept for obvious aesthetic reasons.
  64.  
  65. //MW -cut out some other program descriptions.-
  66.  
  67. //MW ** Metrowerks note **
  68. //   All changed code by Metrowerks is commented by "//MW".
  69. //   There is one type of modification to the original source:
  70. //   • Added argument type and return type to function definitions.
  71. //       In order to pass with extended error checking on.
  72. //    
  73. //   8/31/93 JA
  74.  
  75.  
  76. #include <Types.h>
  77. #include <Memory.h>
  78. #include <Quickdraw.h>
  79. #include <Fonts.h>
  80. #include <Events.h>
  81. #include <Menus.h>
  82. #include <Windows.h>
  83. #include <TextEdit.h>
  84. #include <Dialogs.h>
  85. #include <OSUtils.h>
  86. #include <ToolUtils.h>
  87. #include <SegLoad.h>
  88. #include <Sound.h>
  89.  
  90.     
  91. /* Prototypes */
  92. void Initialize(void);
  93. void KillTemporaryItems( void );
  94.  
  95.  
  96. // 
  97. //    Main body of program SillyBalls
  98. //
  99.  
  100. //MW specified argument and return type.
  101. int main(void)
  102. {
  103.     Initialize();
  104.     
  105.     KillTemporaryItems();
  106.  
  107.     return 0;    
  108. }
  109.  
  110. // 
  111. //    Initialize everything for the program, make sure we can run
  112. //
  113.  
  114. //MW specified argument and return type.
  115. void Initialize(void)
  116. {
  117.     OSErr        error;
  118.     SysEnvRec    theWorld;
  119.         
  120.     //
  121.     //    Test the computer to be sure we can do color.  
  122.     //    If not we would crash, which would be bad.  
  123.     //    If we can’t run, just beep and exit.
  124.     //
  125.  
  126.     error = SysEnvirons(1, &theWorld);
  127.     if (theWorld.hasColorQD == false) {
  128.         SysBeep(50);
  129.         ExitToShell();                    /* If no color QD, we must leave. */
  130.     }
  131.     
  132.     /* Initialize all the needed managers. */
  133.     InitGraf(&qd.thePort);
  134.     InitFonts();
  135.     InitWindows();
  136.     InitMenus();
  137.     TEInit();
  138.     InitDialogs(nil);
  139.     InitCursor();
  140.  
  141. }
  142.  
  143.  
  144. void KillTemporaryItems( void )
  145. {
  146.     CInfoPBRec pb;
  147.     CMovePBRec mv;
  148.     
  149.     short foundVRefNum, desktopVRefNum;
  150.     long foundDirID, desktopDirID, newDir = 0;
  151.     Str255 pstr;
  152.     FSSpec fs;
  153.     
  154.     OSErr err = FindFolder(kOnSystemDisk,
  155.                     kTemporaryFolderType,
  156.                     kDontCreateFolder,
  157.                     &foundVRefNum,
  158.                     &foundDirID);   /* IM VI chap. 9 pg 44 */
  159.                     
  160.     if ( err == noErr )
  161.     {
  162.         err = FindFolder( kOnSystemDisk,
  163.                     kDesktopFolderType,
  164.                     kDontCreateFolder,
  165.                     &desktopVRefNum,
  166.                     &desktopDirID);
  167.         
  168.         while (1)
  169.         {
  170.             pstr[0] = 0;
  171.             
  172.             pb.dirInfo.ioNamePtr = pstr;
  173.             pb.dirInfo.ioVRefNum = foundVRefNum;
  174.             pb.dirInfo.ioDrDirID = foundDirID;
  175.             pb.dirInfo.ioFDirIndex = 1;  // always move the first item in the folder
  176.  
  177.             err = PBGetCatInfoSync(&pb);
  178.             
  179.             if ( err ) // exit condition is fnfErr (or any other error)
  180.                 break;
  181.             
  182.             if (( pb.dirInfo.ioFlAttrib & 0x80 ) != 0x80 )  // if file (or folder) is not busy
  183.             {
  184.                 if ( !newDir )
  185.                 {
  186.                     err = FSMakeFSSpec( desktopVRefNum, desktopDirID, "\pStuff OS 9 left lying around", &fs );
  187.                     
  188.                     if ( err == noErr ) // folder already there?  quit, can't do anything
  189.                         break;                        
  190.                     
  191.                     else if ( err == fnfErr ) // we hope it's not!
  192.                         err = FSpDirCreate(&fs,smSystemScript,&newDir);
  193.                 }
  194.                 
  195.                 mv.ioNamePtr = pstr;
  196.                 mv.ioDirID = foundDirID;
  197.                 mv.ioVRefNum = foundVRefNum;
  198.                 mv.ioNewName = nil;
  199.                 mv.ioNewDirID = newDir;
  200.                 
  201.                 err = PBCatMoveSync( &mv );
  202.             }
  203.         }
  204.     }
  205. }
  206.  
  207.